﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MqttAnalyze.Data.Dal
{
    public class MqttDbDal : BaseSugarDal, IMqttDbDal
    {
        public MqttDbDal(string connectStr)
        {
            base.connectStr = connectStr;
            base.queryDb = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = connectStr,
                DbType = SqlSugar.DbType.Sqlite,
                IsAutoCloseConnection = false
                //ConfigureExternalServices = SqlSugarConfigService.ConfigureMigrateAttributeInfo()
            });
        }

        public void OpenQuery()
        {
            if (queryDb.Ado.Connection.State != ConnectionState.Open)
            {
                queryDb.Open();
            }
        }

        public void CloseQuery()
        {
            base.queryDb.Close();
        }

        public ISqlSugarClient GetClient()
        {
            return base.queryDb;
        }
    }
}
